import urllib.request

# url = "https://www.baidu.com/s?wd=ip"
# headers = {
#     "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"
# }
#
# proxies = {'http': '221.5.80.66:3128'}
#
# handler = urllib.request.ProxyHandler(proxies=proxies)
# opener = urllib.request.build_opener(handler)
# request = urllib.request.Request(url=url,headers=headers)
#
# response = opener.open(request)
# content = response.read().decode('utf-8')
# with open('daili.html','w',encoding='utf-8')as fp:
#     fp.write(content)

from urllib.request import ProxyHandler, build_opener

proxy_handler = ProxyHandler({
    'http': '60.17.206.153:9999'
})

headers = {
    "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"
}

opener = build_opener(proxy_handler)
response = opener.open("http://www.baidu.com/s?wd=ip")
content = response.read().decode('utf-8')

with open('daili.html','w',encoding='utf-8')as fp:
    fp.write(content)